﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Analyzor
{
    public class DbContext
    {

        public static readonly SqlSugarClient StockClient;

        public static readonly SqlSugarClient SourceClient;

        public static readonly SqlSugarClient TargetClient;

        static DbContext()
        {
            StockClient = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = ConfigurationManager.ConnectionStrings["stock"].ConnectionString,
                DbType = DbType.MySql,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute,//从特性读取主键自增信息,
            });

            SourceClient = new SqlSugarClient(new ConnectionConfig
            {
                ConnectionString = ConfigurationManager.ConnectionStrings["src"].ConnectionString,
                DbType = DbType.MySql,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute,//从特性读取主键自增信息,
            });
            TargetClient = new SqlSugarClient(new ConnectionConfig
            {
                ConnectionString = ConfigurationManager.ConnectionStrings["target"].ConnectionString,
                DbType = DbType.MySql,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute,//从特性读取主键自增信息,
            });
        }

        public static SqlSugarClient GetClient(string connection)
        {
            return new SqlSugarClient(new ConnectionConfig
            {
                ConnectionString = ConfigurationManager.ConnectionStrings[connection].ConnectionString,
                DbType = DbType.MySql,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute,//从特性读取主键自增信息,
            });
        }

        public static void Init()
        {

        }
    }
}
